package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-15 11:40
 **/
public class _557_反转字符串中的单词 {

    public String reverseWords(String s) {
        if (s == null || "".equals(s)) {
            return s;
        }

        String[] s1 = s.split(" ");
        for (int i = 0; i < s1.length; i++) {
            s1[i] = revert(s1[i]);
        }
        String join = String.join(" ", s1);
        return join;
    }

    public String revert(String str) {
        if (str == null || "".equals(str)) {
            return "";
        }
        return revert(str.substring(1)) + str.substring(0, 1);
    }
}
